Skip to content

Feature/capr 28 fix sync - #53

Merged
shamikkarkhanis merged 4 commits into
mainfrom
feature/capr-28-fix-sync
Jan 31, 2026
Merged

Feature/capr 28 fix sync#53
shamikkarkhanis merged 4 commits into
mainfrom
feature/capr-28-fix-sync

Conversation

@shamikkarkhanis

@shamikkarkhanis shamikkarkhanis commented Jan 31, 2026

Copy link
Copy Markdown
Member

Summary by Sourcery

Update Discord sync and ping cogs to use injected bot instances and support global plus debug-guild command synchronization, while documenting cog initialization and commit practices.

New Features:

  • Add optional debug guild command synchronization alongside global sync using a configured debug_guild_id.

Enhancements:

  • Refactor Sync and Ping cogs to receive the bot instance via their constructors instead of relying on global state.
  • Improve sync slash command responses with ephemeral handling, clearer logging, and permission checks for administrators only.
  • Extend configuration to support an optional debug_guild_id for targeted guild syncs.

Documentation:

  • Document git commit and pre-commit hook usage and standardize the Cog initialization pattern in AGENTS.md.

- Refactor Sync and Ping cogs to accept bot instance via __init__
- Remove global capy_discord.instance usage in favor of self.bot
- Add debug_guild_id to Settings for guild-specific commands
- Fix /sync to sync both global and debug guild commands
- Add hotswap command for live extension reload
- Add admin permission check to /sync slash command
@sourcery-ai

sourcery-ai Bot commented Jan 31, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Refactors Cog initialization to inject the bot instance, introduces configuration-driven debug guild syncing for application commands, and enhances the sync tooling and documentation around command syncing and development guidelines.

Sequence diagram for updated /sync slash command flow

sequenceDiagram
    actor AdminUser
    participant DiscordClient
    participant SyncCog
    participant DiscordAPI

    AdminUser->>DiscordClient: Invoke /sync
    DiscordClient->>SyncCog: sync_slash(interaction)
    SyncCog->>DiscordClient: interaction.response.defer(ephemeral=true)

    SyncCog->>SyncCog: _sync_commands()
    activate SyncCog
    SyncCog->>DiscordAPI: bot.tree.sync() global commands
    DiscordAPI-->>SyncCog: global_synced
    alt debug_guild_id configured
        SyncCog->>DiscordAPI: bot.tree.sync(guild=debug_guild)
        DiscordAPI-->>SyncCog: guild_synced
    else no debug guild
        SyncCog->>SyncCog: guild_synced = None
    end
    deactivate SyncCog

    SyncCog->>DiscordClient: interaction.followup.send(description, ephemeral=true)

    opt error during sync
        SyncCog->>SyncCog: raise Exception
        alt interaction.response not done
            SyncCog->>DiscordClient: interaction.response.send_message(error, ephemeral=true)
        else response already done
            SyncCog->>DiscordClient: interaction.followup.send(error, ephemeral=true)
        end
    end
Loading

Updated class diagram for Sync, Ping, and Settings

classDiagram
    class commands_Bot

    class Settings {
      +int log_level
      +str prefix
      +str token
      +int debug_guild_id
    }

    class Sync {
      -commands_Bot bot
      -logging_Logger log
      +Sync(bot commands_Bot)
      +_sync_commands() tuple~list~app_commands_AppCommand~~, list~app_commands_AppCommand~~|None~
      +sync(ctx commands_Context) None
      +sync_slash(interaction discord_Interaction) None
    }

    class Ping {
      -commands_Bot bot
      -logging_Logger log
      +Ping(bot commands_Bot)
      +ping(interaction discord_Interaction) None
    }

    class app_commands_AppCommand
    class commands_Context
    class discord_Interaction
    class logging_Logger

    Sync --> commands_Bot : depends on
    Ping --> commands_Bot : depends on
    Sync --> Settings : reads debug_guild_id
    Settings --> commands_Bot : configures behavior
    Sync --> app_commands_AppCommand : sync results
    Sync --> commands_Context : used in sync
    Sync --> discord_Interaction : used in sync_slash
    Ping --> discord_Interaction : used in ping
    Sync --> logging_Logger : logging
    Ping --> logging_Logger : logging
Loading

File-Level Changes

Change Details Files
Refactor Sync cog to use injected bot instance and support global plus optional debug-guild command syncing with improved logging and responses.
  • Change Sync cog constructor to accept and store a commands.Bot instance instead of relying on a global bot instance.
  • Rewrite _sync_commands to sync global commands via the injected bot, optionally sync a configured debug guild from settings.debug_guild_id, and return both command lists.
  • Update text-command !sync to call the new _sync_commands helper for global and debug-guild syncs and adjust user-facing descriptions accordingly.
  • Enhance slash /sync command to be admin-only, defer responses ephemerally, use the updated _sync_commands helper, and provide more detailed success and error messages via followups.
  • Adjust Sync cog setup function to pass the bot instance into the Sync constructor.
capy_discord/exts/tools/sync.py
Align Ping cog with new initialization pattern and use injected bot for latency calculation.
  • Update Ping cog constructor to accept and store the bot instance.
  • Calculate latency from self.bot.latency instead of interaction.client.latency to avoid reliance on the interaction client.
  • Update Ping cog setup to pass the bot instance to the Ping constructor.
capy_discord/exts/tools/ping.py
Extend configuration and docs to support debug guild syncing and codify Cog initialization and commit practices.
  • Add debug_guild_id setting to Settings for configuring an optional debug guild used during command sync.
  • Document git commit and pre-commit hook usage guidelines for contributors.
  • Add documentation section describing the required Cog initialization pattern that takes a bot argument and avoids global instances.
capy_discord/config.py
AGENTS.md

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@shamikkarkhanis
shamikkarkhanis merged commit 3d7ec33 into main Jan 31, 2026
4 checks passed
@shamikkarkhanis
shamikkarkhanis deleted the feature/capr-28-fix-sync branch January 31, 2026 06:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant